import { util } from '../../../../utils/util'
var app = getApp();
//身心健康  体测结果
Page({
  mixins: [],
  data: {
     activityType:'',    //活动类型
     instanceType:'',       //实例类型
     honorFiles:[], //图片数组
     //身高
     height:'',
     sg_gradeArr:[
        {css:'',id:'1',value:'达标'},{css:'',id:'2',value:'不达标'}
    ],
     //体重
     weight:'',
     tz_gradeArr:[
        {css:'',id:'1',value:'达标'},{css:'',id:'2',value:'不达标'}
    ],
     //肺活量
     vitalCapacity:'',
     fhl_gradeArr:[
        {css:'',id:'1',value:'达标'},{css:'',id:'2',value:'不达标'}
    ],
     //50米跑
     meterRun50:'',
     pao_gradeArr:[
        {css:'',id:'1',value:'达标'},{css:'',id:'2',value:'不达标'}
    ],
     //坐立体前屈
     sitandreach:'',
     tqq_gradeArr:[
        {css:'',id:'1',value:'达标'},{css:'',id:'2',value:'不达标'}
    ],
     //立定跳远
     standingLeap:'',
     ty_gradeArr:[
        {css:'',id:'1',value:'达标'},{css:'',id:'2',value:'不达标'}
    ],
     //800米(女)
     meterRun800:'',
     gire_gradeArr:[
        {css:'',id:'1',value:'达标'},{css:'',id:'2',value:'不达标'}
    ],
     //1000米(男)
     meterRun1000:'',
     boy_gradeArr:[
        {css:'',id:'1',value:'达标'},{css:'',id:'2',value:'不达标'}
    ],
     //1分钟仰卧起坐(女)
     sitUP:'',
     ywqz_gradeArr:[
        {css:'',id:'1',value:'达标'},{css:'',id:'2',value:'不达标'}
    ],
     //引体向上(男)
     pullUp:'',
     ytxs_gradeArr:[
        {css:'',id:'1',value:'达标'},{css:'',id:'2',value:'不达标'}
    ]
    },
     sgon_gradesg(e){
      var me = this;
      console.log(e.currentTarget.dataset.index)
      let index=e.currentTarget.dataset.index;
      let arr=me.data.sg_gradeArr;
      let i=0;
      for(;i<arr.length;i++){arr[i].css=''}
      arr[index].css = ' active';
      me.data.height=arr[index].id;
      me.setData( me.data);
    },
    tzon_grade(e){
      var me = this;
      console.log(e.currentTarget.dataset.index)
      let index=e.currentTarget.dataset.index;
      let arr=me.data.tz_gradeArr;
      let i=0;
      for(;i<arr.length;i++){arr[i].css=''}
      arr[index].css = ' active';
      me.data.weight=arr[index].id;
      me.setData( me.data);
    },  
     fhlon_grade(e){
      var me = this;
      console.log(e.currentTarget.dataset.index)
      let index=e.currentTarget.dataset.index;
      let arr=me.data.fhl_gradeArr;
      let i=0;
      for(;i<arr.length;i++){arr[i].css=''}
      arr[index].css = ' active';
      me.data.vitalCapacity=arr[index].id;
      me.setData( me.data);
    },
     paoon_grade(e){
      var me = this;
      console.log(e.currentTarget.dataset.index)
      let index=e.currentTarget.dataset.index;
      let arr=me.data.paogradeArr;
      let i=0;
      for(;i<arr.length;i++){arr[i].css=''}
      arr[index].css = ' active';
      me.data.meterRun50=arr[index].id;
      me.setData( me.data);
    },
     tqqon_grade(e){
      var me = this;
      console.log(e.currentTarget.dataset.index)
      let index=e.currentTarget.dataset.index;
      let arr=me.data.tqqgradeArr;
      let i=0;
      for(;i<arr.length;i++){arr[i].css=''}
      arr[index].css = ' active';
      me.data.sitandreach=arr[index].id;
      me.setData( me.data);
    },
     tyon_grade(e){
      var me = this;
      console.log(e.currentTarget.dataset.index)
      let index=e.currentTarget.dataset.index;
      let arr=me.data.tygradeArr;
      let i=0;
      for(;i<arr.length;i++){arr[i].css=''}
      arr[index].css = ' active';
      me.data.standingLeap=arr[index].id;
      me.setData( me.data);
    },
     grieon_grade(e){
      var me = this;
      console.log(e.currentTarget.dataset.index)
      let index=e.currentTarget.dataset.index;
      let arr=me.data.griegradeArr;
      let i=0;
      for(;i<arr.length;i++){arr[i].css=''}
      arr[index].css = ' active';
      me.data.meterRun800=arr[index].id;
      me.setData( me.data);
    },
     boyon_grade(e){
      var me = this;
      console.log(e.currentTarget.dataset.index)
      let index=e.currentTarget.dataset.index;
      let arr=me.data.boygradeArr;
      let i=0;
      for(;i<arr.length;i++){arr[i].css=''}
      arr[index].css = ' active';
      me.data.meterRun1000=arr[index].id;
      me.setData( me.data);
    },
     ywqzon_grade(e){
      var me = this;
      console.log(e.currentTarget.dataset.index)
      let index=e.currentTarget.dataset.index;
      let arr=me.data.ywqz_gradeArr;
      let i=0;
      for(;i<arr.length;i++){arr[i].css=''}
      arr[index].css = ' active';
      me.data.sitUP=arr[index].id;
      me.setData( me.data);
    },
     ytxson_grade(e){
      var me = this;
      console.log(e.currentTarget.dataset.index)
      let index=e.currentTarget.dataset.index;
      let arr=me.data.ytxs_gradeArr;
      let i=0;
      for(;i<arr.length;i++){arr[i].css=''}
      arr[index].css = ' active';
      me.data.pullUp=arr[index].id;
      me.setData( me.data);
    },

    onSubmit(e) {
      var me = this;
      var obj = e.detail.value;
      var dataObj=obj;
      dataObj['height'] =me.data.height;
      dataObj['weight'] = me.data.weight;
      dataObj['vitalCapacity'] =me.data.vitalCapacity;
      dataObj['meterRun50'] =me.data.meterRun50;
      dataObj['sitandreach'] =me.data.sitandreach;
      dataObj['standingLeap'] =me.data.standingLeap;
      dataObj['meterRun800'] =me.data.meterRun800;
      dataObj['meterRun1000'] =me.data.meterRun1000;
      dataObj['sitUP'] =me.data.sitUP;
      dataObj['pullUp'] = me.data.pullUp;
      //做非空校验
      if(util.validation(dataObj)){
          obj['height'] = parseInt(me.data.height);
          obj['weight'] = parseInt(me.data.weight);
          obj['vitalCapacity'] = parseInt(me.data.vitalCapacity);
          obj['meterRun50'] = parseInt(me.data.meterRun50);
          obj['sitandreach'] = parseInt(me.data.sitandreach);
          obj['standingLeap'] = parseInt(me.data.standingLeap);
          obj['meterRun800'] = parseInt(me.data.meterRun800);
          obj['meterRun1000'] = parseInt(me.data.meterRun1000);
          obj['sitUP'] = parseInt(me.data.sitUP);
          obj['pullUp'] = parseInt(me.data.pullUp);
          obj['files'] = me.data.honorFiles;
          obj['activityType'] = parseInt(me.data.activityType);
          obj['instanceType'] = parseInt(me.data.instanceType);
          console.info(obj);
           var postdata = {
               activityType: parseInt(me.data.activityType),
               instanceType: parseInt(me.data.instanceType),
               itemInfo : obj,
               };
           //调用提交方法
           util.submitRecord(postdata);
      } 
    },
  onLoad(query) {
    // 页面加载
    console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
     var arr = query.honorFiles.split(",");
    this.setData({
      activityType: query.activityType,
      instanceType: query.instanceType,
      honorFiles: arr,
      //身高
     height:'',
     sg_gradeArr:[
        {css:'',id:'1',value:'达标'},{css:'',id:'2',value:'不达标'}
    ],
     //体重
     weight:'',
     tz_gradeArr:[
        {css:'',id:'1',value:'达标'},{css:'',id:'2',value:'不达标'}
    ],
     //肺活量
     vitalCapacity:'',
     fhl_gradeArr:[
        {css:'',id:'1',value:'达标'},{css:'',id:'2',value:'不达标'}
    ],
     //50米跑
     meterRun50:'',
     pao_gradeArr:[
        {css:'',id:'1',value:'达标'},{css:'',id:'2',value:'不达标'}
    ],
     //坐立体前屈
     sitandreach:'',
     tqq_gradeArr:[
        {css:'',id:'1',value:'达标'},{css:'',id:'2',value:'不达标'}
    ],
     //立定跳远
     standingLeap:'',
     ty_gradeArr:[
        {css:'',id:'1',value:'达标'},{css:'',id:'2',value:'不达标'}
    ],
     //800米(女)
     meterRun800:'',
     gire_gradeArr:[
        {css:'',id:'1',value:'达标'},{css:'',id:'2',value:'不达标'}
    ],
     //1000米(男)
     meterRun1000:'',
     boy_gradeArr:[
        {css:'',id:'1',value:'达标'},{css:'',id:'2',value:'不达标'}
    ],
     //1分钟仰卧起坐(女)
     sitUP:'',
     ywqz_gradeArr:[
        {css:'',id:'1',value:'达标'},{css:'',id:'2',value:'不达标'}
    ],
     //引体向上(男)
     pullUp:'',
     ytxs_gradeArr:[
        {css:'',id:'1',value:'达标'},{css:'',id:'2',value:'不达标'}
    ]
    });
  },
  onUnload() {
    // 页面被关闭
    wx.setStorageSync("honorFiles", []);
  },
});
